Automobile Sales in Canada
Graphs of new motor vehicle sales using STATCAN data
Data
STATCAN Table: 20-10-0085-01 - New motor vehicle sales, monthly
Trucks = minivans, sport-utility vehicles, light and heavy trucks, vans and buses
Prepare Data
# Prep data
myCaption <- "derekmichaelwright.github.io/dblogr/ | Data: STATCAN"
myColors_Type <- c("maroon4", "darkslategray")
myColors_Fuel <- c("darkgreen", "darkred")
#
dd <- read.csv("2010008501_databaseLoadingData.csv") %>%
select(Date=REF_DATE, Area=GEO, Vehicle.type, Fuel.type,
Origin.of.manufacture, Unit=UOM, Value=VALUE) %>%
mutate(Date = as.Date(paste0(Date,"-01")))Total Auto Sales
All Vehicles
Canada
# Prep data
xx <- dd %>%
filter(Area == "Canada", Vehicle.type == "Total, new motor vehicles",
Fuel.type == "All fuel types", Unit == "Units",
Origin.of.manufacture == "Total, country of manufacture")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000)) +
geom_line(color = "steelblue4", alpha = 0.7) +
stat_smooth(geom = "line", alpha = 0.8) +
theme_agData(legend.position = "bottom") +
labs(title = "Canada - New Motor Vehicle Sales",
y = "Thousand Sales", x = NULL, caption = myCaption)
ggsave("canada_auto_sales_01.png", mp, width = 6, height = 4)Provinces
# Prep data
xx <- dd %>%
filter(Area != "Canada", Vehicle.type == "Total, new motor vehicles",
Fuel.type == "All fuel types", Unit == "Units",
Origin.of.manufacture == "Total, country of manufacture")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000)) +
geom_line(color = "steelblue4", alpha = 0.7) +
facet_wrap(Area ~ ., scales = "free_y", ncol = 5) +
theme_agData(legend.position = "bottom") +
labs(title = "Canada - New Motor Vehicle Sales",
y = "Thousand Sales", x = NULL, caption = myCaption)
ggsave("canada_auto_sales_02.png", mp, width = 14, height = 6)Vehicle Types
Canada
# Prep data
xx <- dd %>%
filter(Area == "Canada", Vehicle.type != "Total, new motor vehicles",
Fuel.type == "All fuel types", Unit == "Units",
Origin.of.manufacture == "Total, country of manufacture")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, color = Vehicle.type)) +
geom_line(alpha = 0.7) +
scale_color_manual(name = NULL, values = myColors_Type) +
theme_agData(legend.position = "bottom") +
labs(title = "Canada - New Motor Vehicle Sales",
y = "Thousand Sales", x = NULL, caption = myCaption)
ggsave("canada_auto_sales_03.png", mp, width = 6, height = 4)Provinces
# Prep data
xx <- dd %>%
filter(Area != "Canada", Vehicle.type != "Total, new motor vehicles",
Fuel.type == "All fuel types", Unit == "Units",
Origin.of.manufacture == "Total, country of manufacture")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, color = Vehicle.type)) +
geom_line(alpha = 0.7) +
facet_wrap(Area ~ ., scales = "free_y", ncol = 5) +
scale_color_manual(name = NULL, values = myColors_Type) +
theme_agData(legend.position = "bottom") +
labs(title = "Canada - New Motor Vehicle Sales",
y = "Thousand Sales", x = NULL, caption = myCaption)
ggsave("canada_auto_sales_04.png", mp, width = 14, height = 6)Fuel Types
Canada
# Prep data
xx <- dd %>%
filter(Area == "Canada",
Vehicle.type == "Total, new motor vehicles",
Fuel.type %in% c("All other fuel types", "Zero-emission"), Unit == "Units")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, color = Fuel.type)) +
geom_line(alpha = 0.7) +
facet_wrap(Fuel.type ~ ., scales = "free_y") +
scale_color_manual(name = NULL, values = myColors_Fuel) +
theme_agData(legend.position = "bottom") +
labs(title = "Canada - New Motor Vehicle Sales",
y = "Thousand Sales", x = NULL, caption = myCaption)
ggsave("canada_auto_sales_05.png", mp, width = 6, height = 4)Provinces
# Prep data
xx <- dd %>%
filter(Area == "Canada", Vehicle.type != "Total, new motor vehicles",
Fuel.type %in% c("All other fuel types", "Zero-emission"), Unit == "Units")
x1 <- xx %>% filter(Vehicle.type == "Passenger cars")
x2 <- xx %>% filter(Vehicle.type == "Trucks")
# Plot
mp1 <- ggplot(x1, aes(x = Date, y = Value / 1000, color = Fuel.type)) +
geom_line(alpha = 0.7) +
facet_grid(Fuel.type ~ Vehicle.type, scales = "free_y") +
scale_color_manual(name = NULL, values = myColors_Fuel) +
theme_agData(legend.position = "none") +
labs(title = "Canada - New Motor Vehicle Sales",
y = "Thousand Sales", x = NULL)
#
mp2 <- ggplot(x2, aes(x = Date, y = Value / 1000, color = Fuel.type)) +
geom_line(alpha = 0.7) +
facet_grid(Fuel.type ~ Vehicle.type, scales = "free_y") +
scale_color_manual(name = NULL, values = myColors_Fuel) +
theme_agData(legend.position = "none") +
labs(y = "Thousand Sales", x = NULL, caption = myCaption)
#
mp <- ggarrange(mp1, mp2, ncol = 2, align = "h")
ggsave("canada_auto_sales_06.png", mp, width = 7, height = 5, bg = "white")Percent EV
# Prep data
xx <- dd %>%
filter(Area == "Canada", Unit == "Units",
Vehicle.type %in% c("Passenger cars", "Trucks")) %>%
spread(Fuel.type, Value) %>%
filter(!is.na(`Zero-emission`)) %>%
mutate(Percent = 100 * `Zero-emission` / `All fuel types`)
# Plot
mp <- ggplot(xx, aes(x = Date, y = Percent, color = Vehicle.type)) +
geom_line(alpha = 0.7) +
scale_color_manual(name = NULL, values = myColors_Type) +
expand_limits(y = 0) +
theme_agData(legend.position = "bottom") +
labs(title = "Canada - EV Sales",
y = "Percent Sales", x = NULL, caption = myCaption)
ggsave("canada_auto_sales_07.png", mp, width = 6, height = 4)Origin
# Prep data
xx <- dd %>%
filter(Area == "Canada", Vehicle.type == "Total, new motor vehicles",
Fuel.type == "All fuel types", Unit == "Units",
Origin.of.manufacture != "Total, country of manufacture")
# Plot
mp <- ggplot(xx, aes(x = Date, y = Value / 1000, color = Origin.of.manufacture)) +
geom_line(alpha = 0.7) +
scale_color_manual(name = NULL, values = c("steelblue4", "darkred")) +
theme_agData(legend.position = "bottom") +
labs(title = "Canada - New Motor Vehicle Sales",
y = "Thousand Sales", x = NULL, caption = myCaption)
ggsave("canada_auto_sales_08.png", mp, width = 6, height = 4)